//横向簇型图
function DRAWCROSSCLUSTER(url,modelSend,drawContainer) {
    this.draw = function () {
        console.log(modelSend);
        $.ajax({ type: "post",
            url: url,
            dataType: "json",
            data: {"paramData":JSON.stringify(modelSend)},
            success: function (result) {
                console.log(result);
                var dcInstance= new DRAWCLUSTER(result,drawContainer);
                dcInstance.draw(result,drawContainer);
            },
            error: function (err) {
                console.log(err);
            }});
    };
};
//定义一个用于绘制图形的类
function DRAWCLUSTER(json,drawContainer){
    //坐标轴的颜色
    this.colorg=['#f00','#0f0','#00f','#aaf','#faa','#afa'];
    //根据得到的数据绘制Y轴
    this.setYaxis=function(data){
        console.log(data);
        var yaxArray=[];
        for(var i=0;i<data.axis.yCnt;i++){
            var k=i;
            var obj={labels:{format:'{value}',style:{color:''}},title:{text:''}};
            obj.labels.style.color =this.colorg[k];
            if(data.theme.yAxis[k].align=='right'||data.theme.yAxis[k].opposite=='false'){
                obj.labels.format='{value}%';
                obj.opposite='true';
            }
            yaxArray.push(obj);
        }
        return yaxArray;
    };
    //根据得到的数据设置指标
    this.setSeries=function(dataSource){
        var serArray=[];
        for(var key in dataSource.data){
            var obj={};
            var mun=dataSource.data[key].yAxis;
            obj.type=dataSource.theme.yAxis[mun].type;
            //console.log(obj.data);
            obj.name=dataSource.data[key].label;
            obj.data=dataSource.data[key].value;
            obj.color=this.colorg[key];
            obj.zIndex=dataSource.theme.yAxis[mun].type=='line'?1:0;
            obj.yAxis=dataSource.data[key].yAxis;
            obj.dataLabels={enabled: false,
                color: '#000000'};
            serArray.push(obj);
        }
        console.log(serArray);
        return serArray;
    };
    //绘制堆叠柱状图的方法
    this.draw=function(json,container){
        var option={
            chart: {
                type: 'bar'   //横向堆图
            },
            title: {
                text: ''     // 标题
            },
            xAxis: {
                categories: json.axis.x ,  // x 轴分类
                crosshair: true
            },
            yAxis:this.setYaxis(json),
            tooltip: {
                pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.percentage:.2f}%)<br/>',
                shared: true
            },
            plotOptions: {
                bar: {
                    dataLabels: {
                        enabled: true,
                        allowOverlap: true
                    }
                }
            },
            rangeSelector:{
                enabled:false
            },
            legend:{
                align: 'center',
                verticalAlign: 'bottom'
            },
            credits: {//隐藏官网提示
                enabled: false
            },
            exporting: {
                chartOptions: {
                    plotOptions: {
                        series: {
                            dataLabels: {
                                enabled: true
                            }
                        }
                    }
                }
            },
            series:this.setSeries(json)


        };
        console.log(option);
        Highcharts.setOptions({
            lang: {printChart:"打印图表",
                downloadJPEG: "下载JPEG 图片" ,
                downloadPDF: "下载PDF文档"  ,
                downloadPNG: "下载PNG 图片"  ,
                downloadSVG: "下载SVG 矢量图" ,
                exportButtonTitle: "导出图片"
            }
        });
        Highcharts.chart(container,option);

    };
}